package cn.com.jrr.core.common.mytag;

import java.io.IOException;
import java.util.Date;

import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;

import org.springframework.web.servlet.tags.RequestContextAwareTag;

import cn.com.jrr.core.common.StringUtils;

public class TagPopupText extends RequestContextAwareTag {

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private String itemTitle;
    private String itemText;
    private String url;
    private String popupParam;
    private String title;
    private String id;
    private String name;
    private String required;
    private String style;
    @Override
    protected int doStartTagInternal() throws JspTagException{
        String dateStr=String.valueOf(new Date().getTime())+(int)(Math.random()*10000);

        String dialogDivId = "dialogdiv_"+dateStr;
        String tableId = "popuptable_"+dateStr;
        String fuzzySearchId = "fuzzysearchid_"+dateStr;
        String btnSearchId = "btnsearchid_"+dateStr;
        String btnSelectId = "btnselectid"+dateStr;
        JspWriter out = pageContext.getOut();
        StringBuffer sb = new StringBuffer();
        String [] itemTitleArray=null;
        if(StringUtils.isBlank(itemTitle)){
            itemTitleArray=itemTitle.split(",");
        }

        sb.append("<div>\r\n");
        sb.append("<input id='"+id+"' class='easyui-validatebox' type='text' name='"+name+"' required='"+required+"'");
        if(StringUtils.isBlank(style)){
            sb.append(" style='"+style+"'");
        }
        sb.append("></input>\r\n");
        sb.append("<div class='btn-group' role='group' style='position: relative;top:-5px;left:-58px;border:0px;height:'>\r\n");
        sb.append("<button type='button' style='border:0px;background-color:#ffffff;height:28px;' onclick=\"CONSTANT.FUNCTION.popuptextfun(\'"+itemText+"\',\'"+url+"\',\'"+tableId+"\',\'"+dialogDivId+"\',\'"+fuzzySearchId+"\',\'"+btnSearchId+"\',\'"+btnSelectId+"\',\'"+popupParam+"\')\"><span class='fa fa-search'></span></button>\r\n");
        sb.append("<button type='button' style='border:0px;background-color:#ffffff;height:28px;' onclick=\"CONSTANT.FUNCTION.popupdeletetextfun(\'"+popupParam+"\')\"><span class='fa fa-trash'></span></button>\r\n");
        sb.append("</div>\r\n");
        sb.append("<div class='win_hidden_div'>\r\n");
        sb.append("<div id='"+dialogDivId+"' title='"+title+"'>\r\n");

        sb.append("<div class='btn-toolbar'>\r\n");
        sb.append("<div class='pull-right'>\r\n");
        sb.append("<div class='input-append'>\r\n");
        sb.append("<input type='text' placeholder='输入查询关键字' id='"+fuzzySearchId+"'>\r\n");
        sb.append("<div class='btn-group'>\r\n");
        sb.append("<button type='button' class='btn btn-myself btn-sm' id='"+btnSearchId+"'><i class='fa fa-search'></i>查询</button>\r\n");
        sb.append("</div>\r\n");
        sb.append("</div>\r\n");
        sb.append("</div>\r\n");
        sb.append("<button type='button' class='btn btn-myself' id='"+btnSelectId+"'><i class='fa fa-ok'></i> 选择</button>");
        sb.append("</div>\r\n");

        sb.append("<table id='"+tableId+"' class='table table-bordered hover' border='1' width='100%'>\r\n");
        sb.append("<thead>\r\n");
        sb.append("<tr>\r\n");
        sb.append("<th><input type='checkbox' name='cb-check-all'></th>\r\n");
        for(int i=0;i<itemTitleArray.length;i++){
            sb.append("<th>"+itemTitleArray[i]+"</th>\r\n");
        }
        sb.append("</tr>\r\n");
        sb.append("<thead>\r\n");
        sb.append("<tbody></tbody>\r\n");
        sb.append("</table>\r\n");
        sb.append("</div>\r\n");
        sb.append("</div>\r\n");
        sb.append("</div>\r\n");
        //System.out.println(sb.toString());
        try {
            out.print(sb.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return EVAL_PAGE; // 表示处理完标签后继续执行以下的JSP网页
        // return SKIP_PAGE; //表示不处理接下来的JSP网页
    }
    public String getItemTitle() {
        return itemTitle;
    }
    public void setItemTitle(String itemTitle) {
        this.itemTitle = itemTitle;
    }
    public String getItemText() {
        return itemText;
    }
    public void setItemText(String itemText) {
        this.itemText = itemText;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getPopupParam() {
        return popupParam;
    }
    public void setPopupParam(String popupParam) {
        this.popupParam = popupParam;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getRequired() {
        return required;
    }
    public void setRequired(String required) {
        this.required = required;
    }
    public String getStyle() {
        return style;
    }
    public void setStyle(String style) {
        this.style = style;
    }

}
